#include "bullet.h"

Bullet::Bullet()
{
    //加载自动资源
    int rand();
    int a= 1 + rand() % 4;
    if(a==1)m_Bullet.load(BULLET_PATH1);
    if(a==2)m_Bullet.load(BULLET_PATH2);
    if(a==3)m_Bullet.load(BULLET_PATH3);
    if(a==4)m_Bullet.load(BULLET_PATH4);
    if(a==5)m_Bullet.load(BULLET_PATH5);


    //球坐标初始化
    m_X = GAME_WIDTH *0.5 - m_Bullet.width() * 0.5;
    m_Y = GAME_HEIGHT;

    //球空闲状态
    m_Free = true;

    //球速度
    m_Speed = BULLET_SPEED;

    //球矩形边框 （碰撞检测）
    m_Rect.setWidth(m_Bullet.width());
    m_Rect.setHeight(m_Bullet.height());
    m_Rect.moveTo(m_X,m_Y);
}

void Bullet::updatePosition()
{
    //如果球是空闲状态，不需要计算坐标
    if(m_Free)
    {
        return;
    }

    //球移动
    m_Y -=m_Speed;

    m_Rect.moveTo(m_X,m_Y);

    if(m_Y <= - m_Rect.height())
    {
        m_Free = true;
    }

}
